package com.gang.util_demo.service;

import com.alibaba.fastjson.JSON;

import java.util.ArrayList;
import java.util.List;

public class ColsService {
    public String getCols() {
        // 创建表头的数据结构
        List<Object> header = new ArrayList<>();

        // 表1业务汇总
        header.add(new Summary("summary_code", "表1业务汇总"));

        // 本月数据字段
        List<Field> thisMonthFields = new ArrayList<>();
        thisMonthFields.add(new Field("code001", "业务笔数"));
        thisMonthFields.add(new Field("code002", "服务客户数"));
        thisMonthFields.add(new Field("code003", "业务余额"));
        header.add(new Column("本月", thisMonthFields));

        // 上月环比情况数据字段
        List<Field> lastMonthComparisonFields = new ArrayList<>();
        lastMonthComparisonFields.add(new Field("code004", "业务笔数"));
        lastMonthComparisonFields.add(new Field("code005", "服务客户数"));
        lastMonthComparisonFields.add(new Field("code006", "业务余额"));
        header.add(new Column("上月环比情况", lastMonthComparisonFields));

        // 去年本月度同比情况数据字段
        List<Field> lastYearComparisonFields = new ArrayList<>();
        lastYearComparisonFields.add(new Field("code007", "业务笔数"));
        lastYearComparisonFields.add(new Field("code008", "服务客户数"));
        lastYearComparisonFields.add(new Field("code009", "业务余额"));
        header.add(new Column("去年本月度同比情况", lastYearComparisonFields));

        // 将header转换为JSON格式输出
        String json = JSON.toJSONString(header);
        return json;
    }

    // 定义表头中的各个部分的类
    static class Summary {
        private String code;
        private String name;

        public Summary(String code, String name) {
            this.code = code;
            this.name = name;
        }

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }

    static class Column {
        private String column;
        private List<Field> fields;

        public Column(String column, List<Field> fields) {
            this.column = column;
            this.fields = fields;
        }

        public String getColumn() {
            return column;
        }

        public void setColumn(String column) {
            this.column = column;
        }

        public List<Field> getFields() {
            return fields;
        }

        public void setFields(List<Field> fields) {
            this.fields = fields;
        }
    }

    static class Field {
        private String code;
        private String name;

        public Field(String code, String name) {
            this.code = code;
            this.name = name;
        }

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }

}
